cmake_minimum_required(VERSION 3.10)
project(tty_login LANGUAGES CXX)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 查找 SQLite3
find_package(SQLite3 REQUIRED)
if(NOT SQLite3_FOUND)
    message(FATAL_ERROR "SQLite3 not found, install with: sudo apt install libsqlite3-dev")
endif()

# 检查 POSIX 线程库
find_package(Threads REQUIRED)

# 配置可执行文件
add_executable(tty_login
        src/main.cpp
        src/databaseManager.cpp
        src/databaseManager.h
)

# 包含目录
target_include_directories(tty_login PRIVATE
        ${SQLite3_INCLUDE_DIRS}
)

# 链接库
target_link_libraries(tty_login PRIVATE
        ${SQLite3_LIBRARIES}
        Threads::Threads
        dl
)

# 安装规则
install(TARGETS tty_login
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

# 编译器警告
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    target_compile_options(tty_login PRIVATE -Wall -Wextra -Wpedantic)
endif()